/*
 * @Author: xinqiao lxq1990.0716@qq.com
 * @Date: 2023-12-01 15:31:48
 * @LastEditors: xinqiao lxq1990.0716@qq.com
 * @LastEditTime: 2023-12-26 22:06:01
 * @FilePath: \partal\src\router\staticRoutes.ts
 * @Description: 菜单路由
 */

import { getAllMenus } from '@/config/menu'

type MenuType = IParentMenu | IChildMenu

/**
 * 转换菜单为路由
 * @param menus 菜单
 * @returns 
 */
const convertMenuToRouter = (menus: MenuType[]): MenuType[] => {
  return menus.map((menu: MenuType) => {
    const { path, name, component } = menu
    const meta = (menu as IChildMenu).meta
    const children = menu.children ? convertMenuToRouter(menu.children) : []
    return ({ path, name, component, meta, children })
  })
}

const getMenuRouters = async () => convertMenuToRouter(await getAllMenus())

export default getMenuRouters
